package listener;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest;

/**
 * make sure create session at first time if there is no session when requset comming
 * @author zhangyanqi
 * @since 1.0 2017/12/3
 */
public class Listener implements ServletRequestListener {

    /**
     * Receives notification that a ServletRequest is about to go out
     * of scope of the web application.
     *
     * @param sre the ServletRequestEvent containing the ServletRequest
     *            and the ServletContext representing the web application
     */
    public void requestDestroyed(ServletRequestEvent sre) {

    }

    /**
     * Receives notification that a ServletRequest is about to come
     * into scope of the web application.
     *
     * @param sre the ServletRequestEvent containing the ServletRequest
     *            and the ServletContext representing the web application
     */
    public void requestInitialized(ServletRequestEvent sre) {
        ((HttpServletRequest) sre.getServletRequest()).getSession(); //每次请求都带上request
    }
}
